package main.od;

import java.util.Arrays;
import java.util.Scanner;

public class GiftAddress {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] cakePrices = Arrays.stream(sc.nextLine().split(",")).mapToInt(Integer::parseInt).toArray();
        int[] giftPrices = Arrays.stream(sc.nextLine().split(",")).mapToInt(Integer::parseInt).toArray();
        int budget = Integer.parseInt(sc.nextLine());
        int target;
        // 方案数ways
        int ways = 0,way = 0;
        Arrays.sort(giftPrices);
        for (int cakePrice : cakePrices){
            if(cakePrice >= budget){
                continue;
            }
            target = budget - cakePrice;
            // 二分法找到左边界索引值即是满足的方案数
            way = binSearch(giftPrices,target);
            if (way > 0){
                ways += way;
            }
        }
        System.out.println("共有方案： " + ways);
    }

    public static int binSearch(int[] giftPrices,int target){
        int left = 0;
        int right = giftPrices.length - 1;
        while (left <= right){
            int mid = (left + right) >> 1;
            if (giftPrices[mid] > target){
                right = mid - 1;
            }else if(giftPrices[mid] < target){
                left = mid + 1;
            }else {
                // 如果遍历完了或者连续不是相等的值就可以返回了，否则需要继续遍历
                if (mid == giftPrices.length - 1 || giftPrices[mid] != giftPrices[mid + 1]){
                    return mid + 1;
                }else {
                    left = mid + 1;
                }
            }
        }
        return left;
    }

}
